<template>
    <view class="body-view">
        <!--导航和状态栏-->
        <view class="state-navigation">
            <view class="slim_header_navigation d-flex a-center j-center">
                <view class="left_box" @tap="goBack">
                    <image src="/static/center/back.png" class="back"></image>
                </view>
                <view class="title">关于</view>
                <view class="right_box">
                    <!-- <image src="/static/center/dian.png" class="dian"></image> -->
                </view>
            </view>
        </view>
        <!-- 顶部位置占位 -->
        <view style="height: calc(100rpx + var(--status-bar-height))"></view>
        <view class="setUp-all">
            <view class="content-all">
                <view class="content-row d-flex a-center j-between">
                    <view class="row-text">当前版本</view>
                    <view class="row-text">
                        <text v-if="currentVersion&&currentVersion===newVersion" style="color: #48CFA5;font-family: 'din',DINAlternate-Bold, DINAlternate;">{{currentVersion}}</text>
						<text v-else style="color: #FF9858;font-family: 'din',DINAlternate-Bold, DINAlternate;">{{currentVersion}}</text>
						<!--
						<text v-if="currentVersion&&currentVersion===newVersion">(已是最新)</text>
						-->
                        
                    </view>
                </view>
                <view class="content-row d-flex a-center j-between">
                    <view class="row-text">最新版本</view>
                    <view class="row-text" style="color: #48CFA5;font-family: 'din',DINAlternate-Bold, DINAlternate;">{{newVersion}}</view>
                </view>
            </view>
        </view>

        <view class="btn_bottom_box">
                <view class="btn_main_r" v-if="!VER.ver&&currentVersion!==newVersion" @tap="goUpdate">
                    <text class="text">更新</text>
                </view>
                <view class="bottom_seat"></view>
        </view>


        <!--
		<view class="bottom-button w-center d-flex a-center j-center">退出登录</view>
		-->
    </view>
</template>

<script setup lang="tsx" name="setUp">
import { ref } from "vue";
import { onReady, onShow, onHide, onLoad } from "@dcloudio/uni-app";
import { checkUpdate,loginOut } from "@/api/api";
import { userData as userDataStore } from "@/store/userData";
import { config as configStore } from "@/store/config";
import { imStore } from "@/store/imStore";
import { showLoading, closeLoading, wait } from "@/utils/utils";
import { getAppVersion, getPlatform } from "@/utils/utils";
import { loginOut as imLoginOut } from "@/hooks/imLogin";
import { ver } from "@/store/ver";
const VER = ver();
const userData = userDataStore();

const currentVersion = ref("");

const newVersion = ref("");

const goBack = () => {
    uni.navigateBack();
};

const updateMsg = ref({});

const userLoginOut = async () => {
    await imLoginOut();
    const res: any = await loginOut();
    const { flag } = res;
    if (flag === 9000 || flag === 1) {
        userData.clearUserData();
        uni.removeStorageSync("api_token");
        return true;
    }
};

const goUpdate = async () => {
    uni.setStorageSync(
        "updatemsg",
        JSON.parse(JSON.stringify(updateMsg.value))
    );
    await userLoginOut();
    uni.reLaunch({
        url: "/pages/login/login?update=true",
        animationType: "fade-in",
    });
};

const init = async () => {
    /*#ifdef APP-PLUS*/
    const platform = await getPlatform();
    const terminalSysterm = platform === "ios" ? "01" : "02";
    currentVersion.value = await getAppVersion();
    const res = await checkUpdate({ terminalSysterm });

    if (res.flag !== 1) {
        uni.showToast({
            icon: "none",
            title: "获取最新版本信息失败",
            duration: 1500,
        });
        return;
    }

    const { version, updateType, isHot, url } = res.data;

    newVersion.value = version;

    updateMsg.value = res.data;

    ///*#endif*/
};

onLoad(() => {
    init();
});
</script>

<style lang="scss" scoped>
// @import './setUp.scss';
.setUp-all {
    padding: 20rpx;
}
.btn_main {
    position: fixed;
    display: block;
    height: 80rpx;
    border-radius: 40rpx;
    line-height: 80rpx;
    bottom: calc(constant(safe-area-inset-bottom));
    bottom: calc(env(safe-area-inset-bottom));
    z-index: 10;
}
.content-all {
    background: #ffffff;
    border-radius: 10rpx;
    .content-row {
        padding: 0 30rpx;
        height: 100rpx;
        &:active {
            background: #f5f5f5;
        }
        &.noactive {
            background: #fff;
        }
        .row-text {
            font-size: 30rpx;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
        }
        .row-icon {
            flex: 1;
            text-align: right;
            font-size: 20rpx;
            color: #707070;
        }
    }
}

.popup-content {
    position: relative;
    z-index: 1000;
    width: 750rpx;
    border-top-left-radius: 20rpx;
    border-top-right-radius: 20rpx;
    overflow: hidden;
    background: #fff;

    .desp {
        color: #999;
        font-size: 26rpx;
        min-height: 100rpx;
        padding: 20rpx;
    }

    .row {
        height: 100rpx;
    }

    .cancel {
        color: $slim-text3;
    }
}
/*
.bottom-button{
	bottom: 80rpx;
	width: calc(100vw - 60rpx);
	height: 80rpx;
	background: linear-gradient(318deg, #64F1C5 0%, #29DBA3 100%);
	border-radius: 40rpx;
	font-size: 32rpx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	color: #FFFFFF;
}
*/

// /deep/ uni-switch .uni-switch-input:after{
// 	background-color: #23E2A6;
// }
</style>
